//
//  ZJMapNavControllView.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/6/12.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJMapNavControllView.h"

@interface ZJMapNavControllView ()
/**  搜索图片  */
@property (strong, nonatomic) UIImageView  *searImageView;

@end

@implementation ZJMapNavControllView

- (instancetype)initWithFrame:(CGRect)frame leftImage:(NSString *)leftImageString
                   rightImage:(NSString *)rightImageString
    {
        self = [super initWithFrame:frame];
        if (self) {
            /**  添加通知  */
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifiImage:) name:@"changeHeaderImage" object:nil];
            self.backgroundColor = [UIColor themeColor];
            [self addSubview:self.leftButton];
            [self addSubview:self.rightButton];
            [self addSubview:self.searchLabel];
            [self.searchLabel addSubview:self.searImageView];
             [UIImage imageNamed:leftImageString];
            [self.leftButton sd_setImageWithURL:CREATEURL(ZJUSERINFORMODEL.ORG_ACCOUNT.PHOTO_URL) placeholderImage:PlaceholderHeaderImage];
            [self.rightButton setImage:[UIImage imageNamed:rightImageString] forState:UIControlStateNormal];
            
            
        }
        return self;
    }

- (void)notifiImage:(NSNotification *)noti{
    self.leftButton.image = noti.userInfo[@"image"];
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)setNoAddButton{
    self.rightButton.hidden = YES;
    if (self.rightButton.isHidden) {
         self.searchLabel.frame = CGRectMake(self.leftButton.right + 5 * [UIScreen zj_screenWScale], LP_StatusBarHeight + 8, [UIScreen zj_screenWith] - 40 - 24 * [UIScreen zj_screenWScale], 28);
    }else{
         self.searchLabel.frame = CGRectMake(self.leftButton.right + 5 * [UIScreen zj_screenWScale], LP_StatusBarHeight + 8, self.rightButton.x - 32 - 24 * [UIScreen zj_screenWScale], 28);
    }
   
    self.searImageView.frame = CGRectMake(self.searchLabel.width - 28, 4, 20, 20);

    
}

#pragma mark - Setter
    
    
#pragma mark - Getters

- (UIImageView *)leftButton{
    if (!_leftButton) {
        _leftButton = [[UIImageView alloc] initWithFrame:CGRectMake(6 * [UIScreen zj_screenWScale], LP_StatusBarHeight + 6, 32,32 )];
        _leftButton.userInteractionEnabled = YES;
        _leftButton.layer.cornerRadius = 16;
        _leftButton.layer.masksToBounds = YES;
        _leftButton.contentMode = UIViewContentModeScaleToFill;
    }
    return _leftButton;
}
    
- (UIButton *)rightButton{
    if (!_rightButton) {
        _rightButton = [[UIButton alloc] initWithFrame:CGRectMake(self.width - 6 * [UIScreen zj_screenWScale] - 32, LP_StatusBarHeight + 6, 32, 32)];
      
    }
    return _rightButton;
}
    
- (UIImageView *)searImageView{
    if (!_searImageView) {
        _searImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.searchLabel.width - 28, 4, 20, 20)];
        _searImageView.contentMode = UIViewContentModeCenter;
        _searImageView.image = [UIImage imageNamed:@"learn_nav_search"];
    }
    return _searImageView;
}
    
    
- (UILabel *)searchLabel{
    if (!_searchLabel) {
        _searchLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(self.leftButton.right + 5 * [UIScreen zj_screenWScale], LP_StatusBarHeight + 8, [UIScreen zj_screenWith] - LP_TopHeight - 24 * [UIScreen zj_screenWScale], 28)];
            label.textAlignment = NSTextAlignmentLeft;
            label.text = @"   输入关键字快速查找内容";
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor whiteColor];
            label.userInteractionEnabled  = YES;;
            label.layer.cornerRadius = 12;
            label.layer.masksToBounds = YES;
            label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
            
            label;
        });
    }
    return _searchLabel;
}
    


@end
